package com.example.xialingfeng

import android.os.Bundle
import android.util.Log
import android.widget.ArrayAdapter
import android.widget.ListView
import androidx.appcompat.app.AppCompatActivity

class HistoryActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_history)

        val listView = findViewById<ListView>(R.id.listViewHistory)
        val history = loadHistory()
        Log.d("HistoryActivity", "Loaded history: $history")
        val adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, history)
        listView.adapter = adapter
    }

    private fun loadHistory(): List<String> {
        val sharedPreferences = getSharedPreferences("history", MODE_PRIVATE)
        val historySet = sharedPreferences.getStringSet("history_set", emptySet())
        Log.d("HistoryActivity", "History set from SharedPreferences: $historySet")
        return sharedPreferences.getStringSet("history_set", emptySet())?.toList() ?: listOf()
    }
}